package com.xsm.adapter;
import java.util.ArrayList;
import com.xsm.activitygroup.R;

import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class List1Adapter extends BaseAdapter{
	ArrayList<String> values;
	Context context;
	boolean isselect[];
	ViewHolder holder;
	int itembg;
	int itempressbg;
public List1Adapter(ArrayList<String> values,Context context){
	this.values=values;
	this.context=context;
}
public void SetitemPressbg(int itempressbg){
	this.itempressbg=itempressbg;
}
public void Setitembg(int itembg){
	this.itembg=itembg;
}
	public int getCount() {
	return values.size();
	}


	public Object getItem(int arg0) {
		return values.get(arg0);
	}


	public long getItemId(int arg0) {
		return arg0;
	}

	
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		holder=new ViewHolder();
		if(arg1==null){
			arg1=LayoutInflater.from(context).inflate(R.layout.fragment1item, null);
			 holder.bg=(TextView)arg1.findViewById(R.id.text1);
			arg1.setTag(holder);
		}else{
		   holder=(ViewHolder)arg1.getTag();
		}
		
		if(values.size()>0){
		if(isselect[arg0]){
			holder.bg.setBackgroundResource(itempressbg);
		}else {
			holder.bg.setBackgroundResource(itembg);
		}
		holder.bg.setText(values.get(arg0));
		}
		return arg1;
	}

	public void  initselect(){
		isselect=new boolean[values.size()];
		for(int i=0;i<values.size();i++){
			isselect[i]=false;
		}
	}
	public boolean[] getselect(){	
		return isselect;
	}
	
	public void setSelect(int index,boolean select){
		isselect[index]=select;
	}
	class ViewHolder{
		TextView bg;
	}
}
